package br.com.cliquetroca.embedded;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext;

public class EmbeddedServer {
	private final Server server;
	private static Log LOG = LogFactory.getLog(EmbeddedServer.class);
	
	public EmbeddedServer() {
		LOG.info("instanciando servidor");
		server = new Server(8080);
	}

	public static void main(String[] args) throws Exception {
		EmbeddedServer embeddedServer;
		try {
			embeddedServer = new EmbeddedServer();
			
			LOG.info("setando contexto");
			embeddedServer.addHandler(new WebAppContext("src/main/webapp", "/sample"));
			
			LOG.info("iniciando servidor");
			embeddedServer.start();
		} catch (Exception e) {}
	}

	private void start() throws Exception {
		server.start();
	}

	private void addHandler(Handler handler) {
		server.addHandler(handler);
	}
}